package at.btd.bsk.gps;

import android.content.Context;
import at.btd.bsk.entities.TripTime;
import at.btd.bsk.entities.Waypoint;
import at.btd.bsk.observer.Observer;

public class TripStatistics implements Observer<Waypoint> {
	private Context context = null;
	private float averageSpeed = 0.f;
	private float distance = 0;
	private int locationCount = 0;
	private TripTime time = new TripTime(0);
	private Waypoint lastLocation;

	public TripStatistics(Context context) {
		this.context = context;
	}

	public float getDistanceInMeter() {
		return this.distance;
	}

	public float getDistanceInKm() {
		return this.distance / 1000.f;
	}

	public TripTime getTime() {
		return this.time;
	}

	public long getDurationInSeconds() {
		return this.time.getDurationInSeconds();
	}
	
	public float getDurationInMinutes() {
		return getDurationInSeconds() / 60.f;
	}
	
	public float getDurationInHours() {
		return getDurationInSeconds() / 3600.f;
	}

	public float getAverageSpeed() {
		return this.averageSpeed;
	}

	@Override
	public void notify(Waypoint p) {
		if (!this.time.isPaused()) {
			if (this.locationCount > 0) {
				this.distance += p.distanceTo(this.lastLocation);

				this.averageSpeed = getDistanceInKm() / getDurationInHours();
			}
		}

		this.locationCount++;
		this.lastLocation = p;
	}

    public boolean isWaitObserver() {
        // TODO Auto-generated method stub
        return false;
    }
}
